package com.xiaoming.backend.service.impl;

import com.xiaoming.backend.dao.IWareHouseDao;
import com.xiaoming.backend.dto.request.WareHouseRequest;
import com.xiaoming.backend.dto.response.WareHouseResponse;
import com.xiaoming.backend.entity.orm.User;
import com.xiaoming.backend.entity.orm.WareHouse;
import com.xiaoming.backend.service.IWareHouseService;
import com.xiaoming.backend.util.DeepCopyUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class WareHouseServiceImpl implements IWareHouseService {

    private final IWareHouseDao wareHouseDao;
    @Override
    public List<WareHouseResponse> findWareHouse(User user) {
        List<WareHouse> wareHouses = wareHouseDao.selectWareHouse(user.getFacilityId());
        return wareHouses.stream()
                .map(po -> DeepCopyUtil.copyByJackson(po, WareHouseResponse.class))
                .collect(Collectors.toList());
    }

    @Override
    public void updWareHouse(WareHouseRequest wareHouseRequest) {
        wareHouseDao.updateWareHouse(wareHouseRequest.getWarehouseId(), wareHouseRequest.getWarehouseCapacity());
    }
}
